package com.task.controller.annotation.impl;

import com.task.controller.parser.ParameterParser;

import java.lang.reflect.Constructor;
import java.lang.reflect.InvocationTargetException;

public class ParameterImpl {

    public static <T> T createParameterParser(Class<?> cls) throws ClassNotFoundException {
        Constructor<?>[] constructors = cls.getDeclaredConstructors();
        for (Constructor<?> constructor : constructors) {
            if (constructor.getParameterCount() == 0) {
                constructor.setAccessible(true);
                try {
                    return (T) constructor.newInstance();
                } catch (IllegalAccessException | InstantiationException | InvocationTargetException e) {
                    e.printStackTrace();
                }
            }
        }
        throw new ClassNotFoundException(cls.getCanonicalName().concat("没有找到"));
    }
}
